import React from 'react'
// ===================================================================== Temp
import Table from '#cpt/temp/Table'
import TableControls from '#cpt/temp/TableControls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== 
const ControlModal 			= $Lazy.state(()=>import('./control-modal'))
const ControlModalAdd		= $Lazy.state(()=>import('./control-modal-add'))
const ControlModalLook		= $Lazy.state(()=>import('./control-modal-look'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
	}
	
	model = {}
	
	load = ({ bill_phase_id, status, hosp_id, start_at, end_at, bill_start_at, bill_end_at }) => {
		this.query = { bill_phase_id, status:45302, hosp_id, start_at, end_at, bill_start_at, bill_end_at }
		this.model = { current:1 }
		this.fetch()
	}
	
	// 查询项目paging
	fetch = () => $fn.fetch.call(this,'bill/speclists', { isIndex:true })
	
	// 关联表单
	cols = [
		{ title: '条码',				dataIndex: 'old_spec_code', 		...$fn.table.spec_code },
		{ title: '账期',				dataIndex: 'phase_str', 			width:100 },
		{ title: '标本接收时间',		dataIndex: 'sp_check_time', 		...$fn.table.time },
		{ title: '自然项目',			dataIndex: 'category_name', 		width:100 },
		{ title: '账单类型',			dataIndex: 'attribute_name', 		width:100 },
		{ title: '账单创建日期', 	dataIndex: 'bill_created_at', 		...$fn.table.time },
		{ title: '医院名称',			dataIndex: 'hosp_name', 			width:250 },
		{ title: '项目名称',			dataIndex: 'item_name', 			width:250 },
		{ title: '标准价格',			dataIndex: 'sprice', 				...$fn.table.num },
		{ title: '折扣率',			dataIndex: 'percent', 				...$fn.table.num },
		{ title: '实际价格',			dataIndex: 'price', 				...$fn.table.num },
		// 新增初始结算价字段 20211018 耿琰
		{ title: '初始结算价',			dataIndex: 'initial_price', 			...$fn.table.num },
		{ title: '折扣金额',			dataIndex: 'perprice', 				...$fn.table.num },
		{ title: '账单生成时间',		dataIndex: 'created_at', 			...$fn.table.time },
		{ title: '账单状态',			dataIndex: 'status_name', 			...$fn.table.status },
		{ title: '活动详情',			dataIndex: 'content', 				width:200 },	// 增加活动详情 2021-10-27  --马婷 
		{ title: '备注',				dataIndex: 'remark', 				width:150 }, 
		TableControls.controls.call(this,{width:230})
	]
	
	// 表格操作按钮
	table_controls = (text, rows) => {
		return [
			TableControls.click.call(this, '账单信息', ()=> this.modal.open(rows) ),
			TableControls.click.call(this, '新增账单', ()=>this.modaladd.open(rows) ),
			TableControls.click.call(this, '查看其它', ()=>this.modallook.open(rows) ),
		]
	}

	render(){
		return (
			<>
				{/* 表格 */}
				{ Table.call(this,{isIndex:true }) }
				{/* 账单信息 */}
				<ControlModal onRef={ref=>this.modal=ref} />
				{/* 新增账单 */}
				<ControlModalAdd onRef={ref=>this.modaladd=ref} onRefresh={this.fetch} />
				{/* 查看其它 */}
				<ControlModalLook onRef={ref=>this.modallook=ref} onRefresh={this.fetch} />
			</>
		)
	}
}

export default Index